$(function(){
//	获取url传值
	function getQueryString(name) {
		var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
		if (result == null || result.length < 1) {return "";}
			return result[1];
		}
		tid = getQueryString("id");
	$.ajax({
		type:"get",
		url:serverIP+"/user/mainTask/list",
		xhrFields:{
	        withCredentials: true    // 设置sessionId相同
	    },
	    async:false,
		success:function(data){
			let result = data.data.list.result;
			var strVar = "";
            result.map(function(u){
            		if(u.taskId==tid){
		            	if(u.status == "01"){
		                    var status="未开始维护";
		                }else if(u.status == "02"){
		                    var status="正在维护中";
		                }else if(u.status == "03"){
		                    var status="维护完成";
		                }
		                if(u.grade == "01"){
		                	var grade="一级";
		                }else if(u.grade == "02"){
		                	var grade="二级";
		                }else if(u.grade == "03"){
		                	var grade="三级";
		                }
		            	strVar += "              <tr>";
					    strVar += "                <td>"+u.taskId+"<\/td>\n";
					    strVar += "                <td>"+u.taskExplain+"<\/td>\n";
					    strVar += "                <td>"+u.cName+"<\/td>\n";
					    strVar += "                <td>"+u.beginTime+"<\/td>\n";
					    strVar += "                <td>"+u.createTime+"<\/td>\n";
					    strVar += "                <td>"+status+"<\/td>\n";
					    strVar += "                <td>"+grade+"<\/td>\n";
					    strVar += "                <td>"+u.mName+"<\/td>\n";
					    strVar += "                <td>"+u.solution+"<\/td>\n";
					    strVar += "                <td>"+u.remark+"<\/td>\n";
					    strVar += "              <\/tr>";
					    return strVar;
					}
			})				
            $(".print-tbody").html(strVar);
        }
	});
//	故障详情
	$.ajax({
		type:"get",
		url:serverIP+"/user/mainTask/view",
		xhrFields:{
	        withCredentials: true    // 设置sessionId相同
	    },
	    data:{taskId:tid},
		success:function(data){
			let result = data.data.list.result;
			var strVar = "";
            result.map(function(u){
                if(u.urgent == "01"){
                	var urgent="一级";
                }else if(u.urgent == "02"){
                	var urgent="二级";
                }else if(u.urgent == "03"){
                	var urgent="三级";
                }
                var ifMaint=u.ifMaint==true?"已维修":"未维修";
            	strVar += "              <tr>";
			    strVar += "                <td>"+u.codeName,+"<\/td>\n";
			    strVar += "                <td>"+u.origInfo+"<\/td>\n";
			    strVar += "                <td>"+urgent+"<\/td>\n";
			    strVar += "                <td>"+ifMaint+"<\/td>\n";
			    strVar += "              <\/tr>";
			    return strVar;
			})				
            $(".task-tbody").append(strVar);
        }
	});
	$.ajax({
		type:"post",
		url:serverIP+"/user/maint/list",
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
		success:function (data) {
			let result=data.data.list.result;
			result.map(function(u){
				$('select[name="taskp"]').append("<option value="+u.maintId+">"+u.name+"</option>");
			})
		}
	})
})
$('#selectOk').click(function(){
	var mid=$('select[name="taskp"] option:selected').val();
	var mName=$('select[name="taskp"] option:selected').text();
	$.ajax({
		type:"post",
		url:serverIP+"/user/mainTask/save",
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
        data:{taskId:tid,mId:mid},
		success:function (data) {
			if(data.code==0){
				alert("手动派单成功, 维护人员为："+mName);
				window.location.reload();
			}
		}
	})
})
